mapException

inline fun <T> Result<T>.mapException(transform: (Throwable) -> Throwable): Result<T>(source)

Transforms the result exception if it's a failure, otherwise returns itself.

Samples

import dev.kikugie.commons.result.*
import kotlin.test.assertIs
import kotlin.test.assertTrue

fun main() { 
   //sampleStart 
   fun inverse(num: Int): Result<Int> =
    runCatching { 1 / num }

var result = inverse(0)
assertIs<ArithmeticException>(result.exceptionOrNull())

result = result.mapException {
    IllegalArgumentException("Zero is not a valid divisor")
}
assertIs<IllegalArgumentException>(result.exceptionOrNull()) 
   //sampleEnd
}